<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>编辑宿舍房间</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
  <h2>编辑宿舍房间</h2>

  <form th:action="@{/dormrooms/edit/} + ${dormRoom.id}" th:object="${dormRoom}" method="post">
    <div class="mb-3">
      <label class="form-label">宿舍楼</label>
      <select class="form-select" th:field="*{building.id}">
        <option th:each="building : ${buildings}"
                th:value="${building.id}"
                th:text="${building.buildingName}"
                th:selected="${building.id == dormRoom.building.id}"></option>
      </select>
    </div>

    <div class="mb-3">
      <label class="form-label">房间号</label>
      <input type="text" class="form-control" th:field="*{roomNumber}" required>
    </div>

    <div class="mb-3">
      <label class="form-label">房间类型</label>
      <select class="form-select" th:field="*{type.id}">
        <option th:each="type : ${roomTypes}"
                th:value="${type.id}"
                th:text="${type.typeName}"
                th:selected="${type.id == dormRoom.type.id}"></option>
      </select>
    </div>

    <div class="mb-3">
      <label class="form-label">当前人数</label>
      <input type="number" class="form-control" th:field="*{currentCapacity}" required>
    </div>

    <div class="mb-3">
      <label class="form-label">最大容量</label>
      <input type="number" class="form-control" th:field="*{maxCapacity}" required>
    </div>

    <div class="mb-3">
      <label class="form-label">状态</label>
      <select class="form-select" th:field="*{status}">
        <option value="可用" th:selected="${dormRoom.status == '可用'}">可用</option>
        <option value="已满" th:selected="${dormRoom.status == '已满'}">已满</option>
        <option value="维修中" th:selected="${dormRoom.status == '维修中'}">维修中</option>
      </select>
    </div>

    <button type="submit" class="btn btn-primary">保存</button>
    <a th:href="@{/dormrooms/list}" class="btn btn-secondary">取消</a>
  </form>
</div>
</body>
</html>